package com.zhipu.balance.ui.home.calculate.rapeseed.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ScreenUtils
import com.zhipu.balance.R
import com.zhipu.balance.databinding.ItemRiceBinding
import com.zhipu.balance.listener.ChooseClickCallback

/**
 * 稻谷适配器
 */
class RapeseedAdapter(var mChooseClickCallback : ChooseClickCallback) : RecyclerView.Adapter<RapeseedAdapter.ItemViewHolder>() {



    private val mFragmentTitles = arrayOf("杂质", "生芽粒", "生霉粒", "热损伤粒", "未熟粒")
    /**
     * 位置
     */
    private var position = 0

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        val binding = ItemRiceBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ItemViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ItemViewHolder, @SuppressLint("RecyclerView") position: Int) {
        if(this.position == position){
            holder.binding.title.setTextColor(Color.parseColor("#FFFFFF"))
            holder.binding.title.setBackgroundResource(R.drawable.bg_button_10)
        }else{
            holder.binding.title.setTextColor(Color.parseColor("#000000"))
            holder.binding.title.setBackgroundResource(R.drawable.bg_10_f)
        }
        holder.binding.title.text = mFragmentTitles[position]
        holder.binding.title.setOnClickListener {
            if (this.position != position) {
                this.position = position
                mChooseClickCallback.onChooseClickCallback(position)
            }
        }
    }

    override fun getItemCount(): Int {
        return mFragmentTitles.size
    }



    class ItemViewHolder(var binding: ItemRiceBinding) : RecyclerView.ViewHolder(binding.root) {
        init {
            var params = binding.title.layoutParams
            var mScreenHeight = ScreenUtils.getScreenHeight()
            params.height = (mScreenHeight / 5) - 10
            binding.title.layoutParams = params
        }
    }



}